TEMPORALS
Photo by Greg Schneider on Unsplash
A teacher affects eternity: he can never tell where his influence stops…
— Henry Adams
# Load csv data file
df <- read.csv("archetypes/student-teacher-ratios/student-teacher-ratios.csv", header = TRUE, stringsAsFactors = FALSE, encoding = "UTF-8")
df
df_wrangle <- melt(df, id.vars=c("Country", "type"))
df_wrangle$variable <- as.integer(gsub("X", "", df_wrangle$variable))
df_wrangle
df_wrangle <- df_wrangle %>%
filter(type == "Countries") %>%
mutate(country_code = countrycode(Country, "country.name", "iso3c")) %>%
mutate(region = countrycode(country_code, "iso3c", "un.regionsub.name")) %>%
mutate(continent = countrycode(country_code, "iso3c", "continent")) %>%
filter(!is.na(region)) %>%
mutate(year = variable) %>%
mutate(ratio = value)
df_wrangle
df_region <- df_wrangle %>%
group_by(year, region, continent) %>%
summarize(ratio = mean(ratio, na.rm = TRUE)) %>%
filter(!is.nan(ratio))
df_region
df_continent <- df_wrangle %>%
group_by(year, continent) %>%
summarize(ratio = mean(ratio, na.rm = TRUE)) %>%
filter(!is.nan(ratio))
# df_continent
theme_opts <- theme(
text = element_text(family = "inconsolata", size = 10),
plot.title = element_text(color = "black", size = 16, face = "bold"),
plot.subtitle = element_text(color = "black", size = 12),
plot.caption = element_text(color = "#555555", size = 10),
panel.border = element_blank(),
panel.background = element_blank(),
legend.position='none',
panel.spacing.x = unit(1, "lines"),
panel.spacing.y = unit(1, "lines"),
panel.grid.minor = element_blank(),
strip.text = element_text(size = 8.5, face = "bold"),
strip.background = element_blank()
)
continent_palette <- c(
"Asia" = "#171635",
"Europe" = "#00225D",
"Africa" = "#763262",
"Oceania" = "#CA7508",
"Americas" = "#E9A621"
)
# Plot
v1 <- ggplot(df_continent, aes(x = year, y = ratio, color = continent, fill = continent)) +
geom_area(alpha = 0.5) +
# geom_vline(aes(xintercept = year), size = 0.1, color = "gray80") +
facet_wrap( ~ continent, ncol = 1) +
scale_x_continuous(breaks = seq(1970, 2020, by = 10)) +
scale_color_manual(values = continent_palette) +
scale_fill_manual(values = continent_palette) +
labs(title = "Student Teacher Ratios",
subtitle = "by continent",
caption = "Source: UNESCO Institute of Statistics",
x = NULL,
y = NULL) +
theme_bw() +
theme_opts
girafe(ggobj = v1, width_svg = 1080/72, height_svg = 720/72,
options = list(opts_sizing(rescale = FALSE, width = 0.75))
)
list_of_continents <- c("Africa", "Americas", "Asia", "Europe", "Oceania")
p1 <- ggplot(data = subset(df_region, continent == list_of_continents[[1]] ), aes(x = year, y = ratio, color = continent, fill = continent)) +
geom_area(alpha = 0.5) +
facet_wrap( ~ region, nrow = 1) +
scale_x_continuous(breaks = seq(1970, 2020, by = 10)) +
scale_color_manual(values = continent_palette) +
scale_fill_manual(values = continent_palette) +
labs(x = NULL,
y = NULL,
title = list_of_continents[[1]]) +
theme_bw() +
theme_opts
p2 <- ggplot(data = subset(df_region, continent == list_of_continents[[2]] ), aes(x = year, y = ratio, color = continent, fill = continent)) +
geom_area(alpha = 0.5) +
facet_wrap( ~ region, nrow = 1) +
scale_x_continuous(breaks = seq(1970, 2020, by = 10)) +
scale_color_manual(values = continent_palette) +
scale_fill_manual(values = continent_palette) +
labs(x = NULL,
y = NULL,
title = list_of_continents[[2]]) +
theme_bw() +
theme_opts
p3 <- ggplot(data = subset(df_region, continent == list_of_continents[[3]] ), aes(x = year, y = ratio, color = continent, fill = continent)) +
geom_area(alpha = 0.5) +
facet_wrap( ~ region, nrow = 1) +
scale_x_continuous(breaks = seq(1970, 2020, by = 10)) +
scale_color_manual(values = continent_palette) +
scale_fill_manual(values = continent_palette) +
labs(x = NULL,
y = NULL,
title = list_of_continents[[3]]) +
theme_bw() +
theme_opts
p4 <- ggplot(data = subset(df_region, continent == list_of_continents[[4]] ), aes(x = year, y = ratio, color = continent, fill = continent)) +
geom_area(alpha = 0.5) +
facet_wrap( ~ region, nrow = 1) +
scale_x_continuous(breaks = seq(1970, 2020, by = 10)) +
scale_color_manual(values = continent_palette) +
scale_fill_manual(values = continent_palette) +
labs(x = NULL,
y = NULL,
title = list_of_continents[[4]]) +
theme_bw() +
theme_opts
p5 <- ggplot(data = subset(df_region, continent == list_of_continents[[5]] ), aes(x = year, y = ratio, color = continent, fill = continent)) +
geom_area(alpha = 0.5) +
facet_wrap( ~ region, nrow = 1) +
scale_x_continuous(breaks = seq(1970, 2020, by = 10)) +
scale_color_manual(values = continent_palette) +
scale_fill_manual(values = continent_palette) +
labs(x = NULL,
y = NULL,
title = list_of_continents[[5]]) +
theme_bw() +
theme_opts
girafe(code = print(p1 / p2 / p3 / p4 / p5), width_svg = 1080/72, height_svg = 720/72,
options = list(opts_sizing(rescale = FALSE, width = 0.75))
)